package cn.iune.erp.invoice;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;

import com.justep.baas.data.RowState;

//应收应付主表

@Entity
@Table(name = "AccountInvoice"
, uniqueConstraints = { 
		@UniqueConstraint(columnNames = { "accountInvoiceNo", "enterpriseNo" }) 
	}
)
@NamedQuery(name="AccountInvoice.findAll", query="SELECT s FROM AccountInvoice s")
public class AccountInvoice {

	
	@Id
	@Column(length=36)
	private String fID;
	
	@Column(length=32)
	private String systemCode;
	@Column(length=4)
	private String billType;
	@Column(length=20)
	private String billTypeName;
	private Date orderDate;
	@Column(length=10)
	private String state = "active";
	@Column(length=10)
	private String status = "open";
	@Column(length=10)
	private String audit = "active";

	private int flowType = 0;
	@Column(length=1)
	private String revOpay;
	private int direction = 0;
	private Date confirmDate;
	
	@Column(length=4)
	private String origin;
	@Column(length=20)
	private String originName;
	@Column(length=20)
	private String originNo;
	
	@Column(length=20)
	private String accountInvoiceNo;
	
	@Column(length=1)
	private String invoiceCategory;
	@Column(length=20)
	private String invoiceCategoryLabel;
	@Column(length=32)
	private String invoiceCode;
	private Date invoiceDate;
	
	@Column(length=3)
	private String dealObject;
	@Column(length=20)
	private String dealObjectLabel;
	@Column(length=32)
	private String customerID;
	@Column(length=15)
	private String customerNo;
	@Column(length=20)
	private String shortName;
	@Column(length=128)
	private String customerName;

	private int taxType = 0;
	@Column(length=10)
	private String taxTypeLabel;
	@Column(precision=10,scale=2)
	private BigDecimal taxRate = BigDecimal.ZERO;

//	@Column(length=20)
//	private String contacts;
//	@Column(length=20)
//	private String mobilePhone;
//	@Column(length=20)
//	private String fPhone;
	
	@Column(length=20)
	private String taxNo;
	@Column(length=128)
	private String accountBank;
	@Column(length=20)
	private String accountNo;
	
	@Column(length=32)
	private String captionID;//科目编码
	@Column(length=10)
	private String captionNo;
	@Column(length=50)
	private String captionName;
	@Column(length=256)
	private String captionFullName;//科目名称
	
	@Column(precision=10,scale=2)
	private BigDecimal itemAmount = BigDecimal.ZERO;//数量
	
	@Column(precision=38,scale=2)
	private BigDecimal orderAmount;       //应收表：单据金额	 //实收表-主：单据金额	//实收表-从：应收票据余额
	@Column(precision=38,scale=2)
	private BigDecimal orderAmountOld;    //应收表：未税金额	 //实收表：（未使用）
	@Column(precision=38,scale=2)
	private BigDecimal orderAmountTax;    //应收表：税额		 //实收表：（未使用）	
	@Column(precision=38,scale=2)
	private BigDecimal orderAmountTotal;  //应收表：价税合计	 //实收表：实收金额*actualAmount
	
	@Column(precision=38,scale=2)
	private BigDecimal orderAmountCleared; //核销金额
	@Column(precision=38,scale=2,columnDefinition="DECIMAL(38,2) default 0",nullable=false)
	private BigDecimal pendingAmount;	  //应收表：票据余额	 //实收表-主：票据余额
	
	@Column(precision=10,scale=2,columnDefinition="DECIMAL(10,2) default 0")
	private BigDecimal depositRate = BigDecimal.ZERO;//预收定金比例
	
	//折扣率:销售发票中使用（作为客户提前付款的优惠折扣使用，不用参与计算。其他单据不使用）
	@Column(precision=10,scale=2,columnDefinition="DECIMAL(10,2) default 0",nullable=false)
	private BigDecimal discountRate = BigDecimal.ONE;
	
	@Column(precision=38,scale=2,columnDefinition="DECIMAL(38,2) default 0")
	private BigDecimal discountAmount = BigDecimal.ZERO;//整单折扣
	
	//能在审核收款单时将现金折扣更新到销售发票的这个字段。
	@Column(precision=38,scale=2,columnDefinition="DECIMAL(38,2) default 0",nullable=false)
	private BigDecimal discountCash;	  //应收表：现金折扣（见上面）     //实收表-主：现金折扣	//实收表-从：现金折扣
	
	
	@Transient
	@Column(precision=38,scale=2)
	private BigDecimal accountAmountOld;  //应收表：账未税金额//实收表：（未使用）		 
	@Transient
	@Column(precision=38,scale=2)
	private BigDecimal accountAmountTax;  //应收表：账税额	 //实收表：（未使用）	     
	@Transient
	@Column(precision=38,scale=2)
	private BigDecimal accountAmountTotal;//应收表：账价税合计//实收表：账实收金额*accountActual
	@Transient
	@Column(precision=38,scale=2,columnDefinition="DECIMAL(38,2) default 0",nullable=false)
	private BigDecimal accountAmountCleared = BigDecimal.ZERO;//实收表：实收金额（实收）
	@Transient
	@Column(precision=38,scale=2)
	private BigDecimal accountPendingAmount;	  //应收表：账票据余额//实收表：账票据余额
	

	/////////放到零售终端流水号记录中////////////////////////////////////
//	@Column(precision=38,scale=2,columnDefinition="DECIMAL(38,2) default 0",nullable=false)
//	private BigDecimal receiveCashAmount = BigDecimal.ZERO;//收到现金
	//变成计算列
//	@Column(precision=38,scale=2,columnDefinition="DECIMAL(38,2) default 0",nullable=false)
//	private BigDecimal giveChangeAmount = BigDecimal.ZERO;//找零
	////////////////////////////////////////////////////////////////////////
	
	
//	@Column(precision=38,scale=2)
//	private BigDecimal orderAmountCleareding = BigDecimal.ZERO;//正在核销

//	@Column(length=32)
//	private String fMasterID;
	
	@Column(length=32)
	private String paymentTerm;//付款条件
	@Column(length=256)
	private String paymentTermLabel;//优惠券使用描述
	@Column(length=3)
	private String currency;//币种
	@Column(length=20)
	private String currencyLabel;//币种
	@Column(precision=38,scale=6)
	private BigDecimal exchangeRate = BigDecimal.ZERO;//汇率

//	private Date predictDate;//预计到款日
	private Date predictStart;//预计到款日
	private Date predictEnd;//预计兑现日
	
	@Column(columnDefinition="INT default 0",nullable=false)
	private int retailFlag = 0;//批发还是零售（0：批发，1：零售）
	
	@Column(columnDefinition="INT default 0 COMMENT '现结'",nullable=false)
	private int cashSettle = 0;//由销货单自动生成付款单，在收款单录入界面无法删除，只能由销货单撤销审批时删除
	
	@Column(columnDefinition="INT default 0 COMMENT '生成分录'",nullable=false)
	private int entryFlag = 0;//生成分录
	
	//用于现结，写入收款单号。
	@Column(length=4)
	private String next;
	@Column(length=20)
	private String nextName;
	@Column(length=20)
	private String nextNo;

	@Column(length=1)
	private String settleCategory;//结算方式
	@Column(length=20)
	private String settleCategoryLabel;

	@Column(length=15)
	private String orderNo;
	@Column(length=15)
	private String projectNo;

	//门店流水号（客人流水号）
	@Column(length=20)
	private String guestNumber;

	
	@Column(length=20)
	private String resultStatus = "待审核";
//	@Column(length=20)
//	private String paymentStatus = "待核销";
	
	@Column(length=10)
	private String handling = "unclear";//"unclear"：未核销，"clearing"：部分核销，"cleared"：已核销，"finished"：已完成，"cancelled"：已取消
	@Column(length=10)
	private String handlingLabel = "未核销";
	private Timestamp clearDatetime;//核销时间

	private int detailsCount = 0;
	private int detailsCountState = 0;
	
	private int maxDetailNo = 0;

//	@Column(length=65)
//	private String departmentNo;
//	@Column(length=256)
//	private String departmentName;
	@Column(length=256)
	private String employeeNo;
	@Column(length=256)
	private String employeeName;

	@Column(length=255)
	private String comments;
	
	@Column(length=15)
	private String cUsercode;
	@Column(length=20)
	private String cUsername;//制单人
	private Timestamp cDatetime;
	@Column(length=15)
	private String tUsercode;
	@Column(length=20)
	private String tUsername;//审核人
	private Timestamp tDatetime;
	@Column(length=15)
	private String eUsercode;
	@Column(length=20)
	private String eUsername;//关单人
	private Timestamp eDatetime;
	
	@Column(length=65)
	private String userId;

	@Column(length=128)
	private String enterpriseNo;
	@Column(length=128)
	private String enterpriseName;

	///////////////////////////////////////////
//	private String settleCategory;
//	private String settleCode;

	@Version
	private int version = 0;
	
	@Transient//非持久字段
	private RowState rowState;
	public RowState getRowState() {
		return rowState;
	}
	public void setRowState(RowState rowState) {
		this.rowState = rowState;
	}
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
	
	public String getOriginName() {
		return originName;
	}

	public Date getInvoiceDate() {
		return invoiceDate;
	}

	public void setInvoiceDate(Date invoiceDate) {
		this.invoiceDate = invoiceDate;
	}

	public String getDealObjectLabel() {
		return dealObjectLabel;
	}

	public void setDealObjectLabel(String dealObjectLabel) {
		this.dealObjectLabel = dealObjectLabel;
	}

	public String getcUsercode() {
		return cUsercode;
	}

	public void setcUsercode(String cUsercode) {
		this.cUsercode = cUsercode;
	}

	public String getcUsername() {
		return cUsername;
	}

	public void setcUsername(String cUsername) {
		this.cUsername = cUsername;
	}

	public Timestamp getcDatetime() {
		return cDatetime;
	}

	public void setcDatetime(Timestamp cDatetime) {
		this.cDatetime = cDatetime;
	}

	public String gettUsercode() {
		return tUsercode;
	}

	public void settUsercode(String tUsercode) {
		this.tUsercode = tUsercode;
	}

	public String gettUsername() {
		return tUsername;
	}

	public void settUsername(String tUsername) {
		this.tUsername = tUsername;
	}

	public Timestamp gettDatetime() {
		return tDatetime;
	}

	public void settDatetime(Timestamp tDatetime) {
		this.tDatetime = tDatetime;
	}

	public String geteUsercode() {
		return eUsercode;
	}

	public void seteUsercode(String eUsercode) {
		this.eUsercode = eUsercode;
	}

	public String geteUsername() {
		return eUsername;
	}

	public void seteUsername(String eUsername) {
		this.eUsername = eUsername;
	}

	public Timestamp geteDatetime() {
		return eDatetime;
	}

	public void seteDatetime(Timestamp eDatetime) {
		this.eDatetime = eDatetime;
	}

	public void setOriginName(String originName) {
		this.originName = originName;
	}

	public String getInvoiceCategoryLabel() {
		return invoiceCategoryLabel;
	}

	public void setInvoiceCategoryLabel(String invoiceCategoryLabel) {
		this.invoiceCategoryLabel = invoiceCategoryLabel;
	}

	public String getBillTypeName() {
		return billTypeName;
	}

	public void setBillTypeName(String billTypeName) {
		this.billTypeName = billTypeName;
	}

	public String getSystemCode() {
		return systemCode;
	}

	public void setSystemCode(String systemCode) {
		this.systemCode = systemCode;
	}

	public int getDetailsCountState() {
		return detailsCountState;
	}

	public void setDetailsCountState(int detailsCountState) {
		this.detailsCountState = detailsCountState;
	}

	public int getFlowType() {
		return flowType;
	}

	public void setFlowType(int flowType) {
		this.flowType = flowType;
	}

	public String getAudit() {
		return audit;
	}

	public void setAudit(String audit) {
		this.audit = audit;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getProjectNo() {
		return projectNo;
	}

	public void setProjectNo(String projectNo) {
		this.projectNo = projectNo;
	}

	public int getDetailsCount() {
		return detailsCount;
	}


	public Date getConfirmDate() {
		return confirmDate;
	}

	public void setConfirmDate(Date confirmDate) {
		this.confirmDate = confirmDate;
	}

	public String getRevOpay() {
		return revOpay;
	}

	public void setRevOpay(String revOpay) {
		this.revOpay = revOpay;
	}

	public String getfID() {
		return fID;
	}
	public void setfID(String fID) {
		this.fID = fID;
	}
	public String getAccountInvoiceNo() {
		return accountInvoiceNo;
	}
	public void setAccountInvoiceNo(String accountInvoiceNo) {
		this.accountInvoiceNo = accountInvoiceNo;
	}
	public String getCustomerNo() {
		return customerNo;
	}
	public void setCustomerNo(String customerNo) {
		this.customerNo = customerNo;
	}
	public String getCustomerName() {
		return customerName;
	}
	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}
	public BigDecimal getOrderAmount() {
		return orderAmount;
	}
	public void setOrderAmount(BigDecimal orderAmount) {
		this.orderAmount = orderAmount;
	}
	public BigDecimal getOrderAmountOld() {
		return orderAmountOld;
	}
	public void setOrderAmountOld(BigDecimal orderAmountOld) {
		this.orderAmountOld = orderAmountOld;
	}
	public BigDecimal getOrderAmountTax() {
		return orderAmountTax;
	}
	public void setOrderAmountTax(BigDecimal orderAmountTax) {
		this.orderAmountTax = orderAmountTax;
	}
	public BigDecimal getItemAmount() {
		return itemAmount;
	}

	public void setItemAmount(BigDecimal itemAmount) {
		this.itemAmount = itemAmount;
	}

	public int getDirection() {
		return direction;
	}

	public void setDirection(int direction) {
		this.direction = direction;
	}

	public BigDecimal getOrderAmountTotal() {
		return orderAmountTotal;
	}
	public void setOrderAmountTotal(BigDecimal orderAmountTotal) {
		this.orderAmountTotal = orderAmountTotal;
	}
	public BigDecimal getAccountAmountTotal() {
		return accountAmountTotal;
	}
	public void setAccountAmountTotal(BigDecimal accountAmountTotal) {
		this.accountAmountTotal = accountAmountTotal;
	}
	public BigDecimal getAccountAmountTax() {
		return accountAmountTax;
	}
	public void setAccountAmountTax(BigDecimal accountAmountTax) {
		this.accountAmountTax = accountAmountTax;
	}
	public BigDecimal getAccountAmountOld() {
		return accountAmountOld;
	}

	public void setAccountAmountOld(BigDecimal accountAmountOld) {
		this.accountAmountOld = accountAmountOld;
	}

	public String getOrigin() {
		return origin;
	}
	public void setOrigin(String origin) {
		this.origin = origin;
	}
	public String getEnterpriseNo() {
		return enterpriseNo;
	}
	public void setEnterpriseNo(String enterpriseNo) {
		this.enterpriseNo = enterpriseNo;
	}
	public String getEnterpriseName() {
		return enterpriseName;
	}
	public void setEnterpriseName(String enterpriseName) {
		this.enterpriseName = enterpriseName;
	}
	public int getMaxDetailNo() {
		return maxDetailNo;
	}
	public void setMaxDetailNo(int maxDetailNo) {
		this.maxDetailNo = maxDetailNo;
	}
	public String getDealObject() {
		return dealObject;
	}
	public void setDealObject(String dealObject) {
		this.dealObject = dealObject;
	}
	public String getShortName() {
		return shortName;
	}
	public void setShortName(String shortName) {
		this.shortName = shortName;
	}
	public String getInvoiceCategory() {
		return invoiceCategory;
	}
	public void setInvoiceCategory(String invoiceCategory) {
		this.invoiceCategory = invoiceCategory;
	}
	public String getInvoiceCode() {
		return invoiceCode;
	}
	public void setInvoiceCode(String invoiceCode) {
		this.invoiceCode = invoiceCode;
	}
	public Date getOrderDate() {
		return orderDate;
	}
	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
	public String getEmployeeNo() {
		return employeeNo;
	}
	public void setEmployeeNo(String employeeNo) {
		this.employeeNo = employeeNo;
	}
	public String getEmployeeName() {
		return employeeName;
	}
	public void setEmployeeName(String employeeName) {
		this.employeeName = employeeName;
	}
	public String getComments() {
		return comments;
	}
	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getBillType() {
		return billType;
	}

	public void setBillType(String billType) {
		this.billType = billType;
	}

	public String getOriginNo() {
		return originNo;
	}

	public void setOriginNo(String originNo) {
		this.originNo = originNo;
	}

	public void setDetailsCount(int detailsCount) {
		this.detailsCount = detailsCount;
	}
	public String getCustomerID() {
		return customerID;
	}
	public void setCustomerID(String customerID) {
		this.customerID = customerID;
	}
	public int getTaxType() {
		return taxType;
	}
	public void setTaxType(int taxType) {
		this.taxType = taxType;
	}
	public String getTaxTypeLabel() {
		return taxTypeLabel;
	}
	public void setTaxTypeLabel(String taxTypeLabel) {
		this.taxTypeLabel = taxTypeLabel;
	}
	public BigDecimal getTaxRate() {
		return taxRate;
	}
	public void setTaxRate(BigDecimal taxRate) {
		this.taxRate = taxRate;
	}
	public String getTaxNo() {
		return taxNo;
	}
	public void setTaxNo(String taxNo) {
		this.taxNo = taxNo;
	}
	public String getAccountBank() {
		return accountBank;
	}
	public void setAccountBank(String accountBank) {
		this.accountBank = accountBank;
	}
	public String getAccountNo() {
		return accountNo;
	}
	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}
	public String getOrderNo() {
		return orderNo;
	}
	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}
	public String getResultStatus() {
		return resultStatus;
	}
	public void setResultStatus(String resultStatus) {
		this.resultStatus = resultStatus;
	}


	public String getHandling() {
		return handling;
	}
	public void setHandling(String handling) {
		this.handling = handling;
	}
	public String getHandlingLabel() {
		return handlingLabel;
	}
	public void setHandlingLabel(String handlingLabel) {
		this.handlingLabel = handlingLabel;
	}
	public String getNext() {
		return next;
	}
	public void setNext(String next) {
		this.next = next;
	}
	public String getNextName() {
		return nextName;
	}
	public void setNextName(String nextName) {
		this.nextName = nextName;
	}
	public String getNextNo() {
		return nextNo;
	}
	public void setNextNo(String nextNo) {
		this.nextNo = nextNo;
	}

	public String getPaymentTerm() {
		return paymentTerm;
	}
	public void setPaymentTerm(String paymentTerm) {
		this.paymentTerm = paymentTerm;
	}
	public String getPaymentTermLabel() {
		return paymentTermLabel;
	}
	public void setPaymentTermLabel(String paymentTermLabel) {
		this.paymentTermLabel = paymentTermLabel;
	}

	public Date getPredictStart() {
		return predictStart;
	}
	public void setPredictStart(Date predictStart) {
		this.predictStart = predictStart;
	}
	public Date getPredictEnd() {
		return predictEnd;
	}
	public void setPredictEnd(Date predictEnd) {
		this.predictEnd = predictEnd;
	}
	public String getSettleCategory() {
		return settleCategory;
	}
	public void setSettleCategory(String settleCategory) {
		this.settleCategory = settleCategory;
	}
	public String getSettleCategoryLabel() {
		return settleCategoryLabel;
	}
	public void setSettleCategoryLabel(String settleCategoryLabel) {
		this.settleCategoryLabel = settleCategoryLabel;
	}
	public BigDecimal getDiscountRate() {
		return discountRate;
	}
	public void setDiscountRate(BigDecimal discountRate) {
		this.discountRate = discountRate;
	}

	public BigDecimal getDiscountCash() {
		return discountCash;
	}
	public void setDiscountCash(BigDecimal discountCash) {
		this.discountCash = discountCash;
	}
	public Timestamp getClearDatetime() {
		return clearDatetime;
	}
	public void setClearDatetime(Timestamp clearDatetime) {
		this.clearDatetime = clearDatetime;
	}
	public String getCaptionID() {
		return captionID;
	}
	public void setCaptionID(String captionID) {
		this.captionID = captionID;
	}
	public String getCaptionNo() {
		return captionNo;
	}
	public void setCaptionNo(String captionNo) {
		this.captionNo = captionNo;
	}
	public String getCaptionName() {
		return captionName;
	}
	public void setCaptionName(String captionName) {
		this.captionName = captionName;
	}
	public String getCaptionFullName() {
		return captionFullName;
	}
	public void setCaptionFullName(String captionFullName) {
		this.captionFullName = captionFullName;
	}
	public BigDecimal getPendingAmount() {
		return pendingAmount;
	}
	public void setPendingAmount(BigDecimal pendingAmount) {
		this.pendingAmount = pendingAmount;
	}
	public BigDecimal getDepositRate() {
		return depositRate;
	}
	public void setDepositRate(BigDecimal depositRate) {
		this.depositRate = depositRate;
	}
	public int getCashSettle() {
		return cashSettle;
	}
	public void setCashSettle(int cashSettle) {
		this.cashSettle = cashSettle;
	}
	public BigDecimal getOrderAmountCleared() {
		return orderAmountCleared;
	}
	public void setOrderAmountCleared(BigDecimal orderAmountCleared) {
		this.orderAmountCleared = orderAmountCleared;
	}
	public BigDecimal getDiscountAmount() {
		return discountAmount;
	}
	public void setDiscountAmount(BigDecimal discountAmount) {
		this.discountAmount = discountAmount;
	}
	public String getGuestNumber() {
		return guestNumber;
	}
	public void setGuestNumber(String guestNumber) {
		this.guestNumber = guestNumber;
	}
	public String getCurrency() {
		return currency;
	}
	public void setCurrency(String currency) {
		this.currency = currency;
	}
	public String getCurrencyLabel() {
		return currencyLabel;
	}
	public void setCurrencyLabel(String currencyLabel) {
		this.currencyLabel = currencyLabel;
	}
	public BigDecimal getExchangeRate() {
		return exchangeRate;
	}
	public void setExchangeRate(BigDecimal exchangeRate) {
		this.exchangeRate = exchangeRate;
	}
	public int getRetailFlag() {
		return retailFlag;
	}
	public void setRetailFlag(int retailFlag) {
		this.retailFlag = retailFlag;
	}
	public BigDecimal getAccountPendingAmount() {
		return accountPendingAmount;
	}
	public void setAccountPendingAmount(BigDecimal accountPendingAmount) {
		this.accountPendingAmount = accountPendingAmount;
	}
	public BigDecimal getAccountAmountCleared() {
		return accountAmountCleared;
	}
	public void setAccountAmountCleared(BigDecimal accountAmountCleared) {
		this.accountAmountCleared = accountAmountCleared;
	}
	public int getEntryFlag() {
		return entryFlag;
	}
	public void setEntryFlag(int entryFlag) {
		this.entryFlag = entryFlag;
	}


	

}
